*This file creates municipal-level measure of 1970 industrial development


*Use the ready-made 70-85 dataset
use "D:\ready-made\FOLK_vl_7085\vl7085_1.dta" if vuosi==1970, clear
destring ika, replace
keep if ika>17&ika<66

*Generate share of industries in municipalities
keep toimiala kunta 
gen toimiala_3=substr(toimiala,1,3)
tab toimiala_3
gen individual=1
collapse (sum) individual, by(toimiala_3 kunta)
bys kunta: egen all=sum(individual)
gen share_ind=individual/all
drop individual all


preserve
*Add the Leontief shocks
joinby toimiala_3 using "$temp\upstream_downstream_toimiala3.dta"
*Same as bartik formula
gen upward=U_repa*share_ind
gen downward=D_repa*share_ind
collapse (sum) U D upward downward, by(kunta)
replace upward=upward/U
replace downward=downward/D
tempfile updown
save `updown'
restore


*Calculate industry education and capital intensity (from Ciccone and Papaionau) 
*Matched to finnish industry classifications
gen capint=0.730 if toimiala_3=="314"
replace capint=2.316 if toimiala_3=="361"
replace capint=0.663 if toimiala_3=="323"
replace capint=0.443 if toimiala_3=="324"
replace capint=2.103 if toimiala_3=="372"
replace capint=0.481 if toimiala_3=="322"
replace capint=2.593 if toimiala_3=="353"
replace capint=1.746 if toimiala_3=="369"
replace capint=1.744 if toimiala_3=="313"
replace capint=3.194 if toimiala_3=="371"
replace capint=1.366 if toimiala_3=="311"
replace capint=2.215 if toimiala_3=="341"
replace capint=1.807 if toimiala_3=="321"
replace capint=0.785 if toimiala_3=="342"
replace capint=2.265 if toimiala_3=="355"
replace capint=0.789 if toimiala_3=="332"
replace capint=1.173 if toimiala_3=="381"
replace capint=2.385 if toimiala_3=="351"
replace capint=1.632 if toimiala_3=="331"
replace capint=1.199 if toimiala_3=="354"
replace capint=1.320 if toimiala_3=="384"
replace capint=0.878 if toimiala_3=="390"
replace capint=1.954 if toimiala_3=="362"
replace capint=1.017 if toimiala_3=="382"
replace capint=0.800 if toimiala_3=="352"
replace capint=0.924 if toimiala_3=="383"
replace capint=0.654 if toimiala_3=="385"
replace capint=1.416 if toimiala_3=="356"


gen hcint=11.509 if toimiala_3=="314"
replace hcint=11.244 if toimiala_3=="361"
replace hcint=10.138 if toimiala_3=="323"
replace hcint=10.259 if toimiala_3=="324"
replace hcint=11.547 if toimiala_3=="372"
replace hcint=10.193 if toimiala_3=="322"
replace hcint=13.204 if toimiala_3=="353"
replace hcint=11.655 if toimiala_3=="369"
replace hcint=11.9674 if toimiala_3=="313"
replace hcint=11.435 if toimiala_3=="371"
replace hcint=11.259 if toimiala_3=="311"
replace hcint=11.693 if toimiala_3=="341"
replace hcint=10.397 if toimiala_3=="321"
replace hcint=12.792 if toimiala_3=="342"
replace hcint=11.730 if toimiala_3=="355"
replace hcint=10.760 if toimiala_3=="332"
replace hcint=11.577 if toimiala_3=="381"
replace hcint=12.704 if toimiala_3=="351"
replace hcint=10.787 if toimiala_3=="331"
replace hcint=11.921 if toimiala_3=="354"
replace hcint=12.346 if toimiala_3=="384"
replace hcint=11.354 if toimiala_3=="390"
replace hcint=11.484 if toimiala_3=="362"
replace hcint=12.266 if toimiala_3=="382"
replace hcint=13.031 if toimiala_3=="352"
replace hcint=12.357 if toimiala_3=="383"
replace hcint=12.518 if toimiala_3=="385"
replace hcint=11.678 if toimiala_3=="356"


gen hcint1=hcint*share_ind
gen capint1=capint*share_ind

keep  hcint1 capint1 kunta toimiala_3
reshape wide hcint1 capint1 ,i(kunta) j(toimiala_3) string


egen education_index=rowmean(hcint1*)
egen capital_intensity=rowmean(capint1*)
drop hcint1* capint1*


*Join the war reparations shock to the municipality
preserve
use "$temp\municipality_shares_bartik_1939.dta" , clear
keep  bartik*  mun39 share*   individual ln_area ln_pop_1940 manushare_1940  agrishare_1940 share_service_1940 ///
share_construction_1940  displaced_share_1940 swedish_share_1940 average_incometax_38 income_tax_payers38 ln_arable_1940  ln_salary ///
relative_cows1940 relative_tractors1940 displaced_share_1940 swedish_share_1940  railway laani50 city town  changeagri change_tax_payers 
xtile  manu_quartile=manushare_1940 , nq(4)
xtile  agri_quartile=agrishare_1940 , nq(4)
drop bartik_standardized 
egen bartik_standardized=std(bartik) 
egen bartiknotimber_st=std(bartiknotimber)
egen bartikhs_st=std(bartikhs)
egen bartikls_st=std(bartikls)
xtile  bartik_cluster=bartik_standardized , nq(50)
xtile  bartik_decile=bartik_standardized , nq(10)
xtile  bartik_quartile=bartik_standardized , nq(4)
xtile  bartik_h=bartik_standardized , nq(2)
gen bartik_high=bartik_h==2
gen bartikq2=(bartik_quartile==2)
gen bartikq3=(bartik_quartile==3)
gen bartikq4=(bartik_quartile==4)
rename mun39 kunta
tempfile shiftshare
save `shiftshare'
restore


joinby kunta using `shiftshare', unmatched(master)

drop _merge
joinby kunta using `updown', unmatched(master)


gen mun39=kunta
destring mun39, replace


*1939 measures for controls 
drop _merge
joinby mun39 using "$temp\bartik_down_up_leontief.dta", unmatched(master)
*Fix outliers
replace bartik_u_st=. if bartik_u_st>5
replace bartik_d_st=. if bartik_d_st>5


*1939 industry measures for controls 
count
drop _merge
joinby mun39 using "$temp\education_capital_index_1939.dta", unmatched(master)
count


*Scale variables
replace upward=upward*100
replace downward=downward*100
replace capital_intensity=capital_intensity*100
replace education_index=education_index*100

global municontrols  agrishare_1940 manushare_1940  town city      

*Clean some extreme outliers
replace capital_intensity=.  if capital_intensity>10
replace education_index=.  if education_index>40


*Regressions

reg upward  bartik_standardized  $municontrols [aw=indi]  , a(laani50) r
sum upward 
estadd scalar ymean=r(mean)
estimates store up1

reg upward  bartik_standardized   bartik_u_st   $municontrols [aw=indi] , a(laani50) r
sum upward 
estadd scalar ymean=r(mean)
estimates store up2


reg downward  bartik_standardized  $municontrols [aw=indi], a(laani50) r
sum downward
estadd scalar ymean=r(mean)
estimates store down1

reg downward  bartik_standardized bartik_d_st $municontrols [aw=indi], a(laani50) r
sum downward
estadd scalar ymean=r(mean)
estimates store down2


reg capital_intensity  bartik_standardized  $municontrols [aw=indi], a(laani50) r
sum capital_intensity
estadd scalar ymean=r(mean)
estimates store c1

reg capital_intensity  bartik_standardized capital_intensity1939 $municontrols [aw=indi], a(laani50) r
sum capital_intensity
estadd scalar ymean=r(mean)
estimates store c2

reg education_index  bartik_standardized  $municontrols [aw=indi], a(laani50) r
sum education_index
estadd scalar ymean=r(mean)
estimates store e1

reg education_index  bartik_standardized education_index1939 $municontrols [aw=indi], a(laani50) r
sum education_index
estadd scalar ymean=r(mean)
estimates store e2


labe var bartik_u_st "Exposure Upstream 1939"
labe var bartik_d_st "Exposure Downstream 1939"
labe var capital_intensity1939 "Capital Intensity 1939"
labe var education_index1939 "Human Capital Index 1939"


label var bartik_standardized "Exposure"

esttab  up1 up2 down1 down2 c1 c2 e1 e2  ///
using "$temp\tables\industry_1970.tex", ///
mgroups("Upstream Employment" "Downstream Employment"  "Capital Intensity" "Human Capital Intensity", pattern(1 0 1 0 1 0 1 0) prefix(\multicolumn{@span}{c}{) suffix(}) ///
span erepeat(\cmidrule(lr){@span}) ) ///
replace keep(bartik_standardized bartik_u_st bartik_d_st capital_intensity1939 education_index1939) nonotes ///
b(%9.3f) se(%9.3f)  stats(N  ymean , fmt(0 3) layout(@ @) ///
labels("N"  "Y mean")) label star(* .1 ** .05 *** .01) nodepvars nomtitle




